package com.yoomiito.app.present.my.activity;


import com.yoomiito.app.Constant;
import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.cicle.CicleRecommendInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.my.MyPublishMaterialActivity;
import com.yoomiito.app.utils.NetworkUtils;
import com.yoomiito.app.utils.YMToast;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class MyPublishMaterialPresenter extends BaseActPresenter<MyPublishMaterialActivity> {

    public MyPublishMaterialPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getPublishMaterialData(int type,int page){
        if (NetworkUtils.checkNetPermission(getV())){
            getV().finishRefresh();
            return;
        }
        YmApi.getYmService()
                .geGoodsRecommendData(type,page,Constant.PAGE_SIZE)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<CicleRecommendInfo>getApiTransformerData())
                .compose(XApi.<CicleRecommendInfo>getScheduler())
                .subscribe(new ApiSubscriber<CicleRecommendInfo>() {
                    @Override
                    public void onSuccess(CicleRecommendInfo data) {
                        getV().setPublishMaterialData(data);
                    }
                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText("error");
                    }
                });
    }

}
